*******************************************************************************
* Load candidates data
*******************************************************************************

use dataset_candidates, clear

*******************************************************************************
* Put the rating variables in a macro
*******************************************************************************

forvalues i = 1(1)116 {
	local rtr `rtr' tradrtr`i'_
	local rtr `rtr' progrtr`i'_
	local rtr `rtr' otherrtr`i'_
	local rtr `rtr' nonertr`i'_
}

*******************************************************************************
* Re-shape to bullet level
*******************************************************************************

keep text* *rtr* *gold*
drop if mi(text1)
gen id = _n
reshape i id
reshape j bullet
reshape xij text `rtr' goldtext 
reshape xi
reshape long
duplicates drop text, force

*******************************************************************************
* Get inter-coder agreement
*******************************************************************************

forvalues i = 1(1)116 {
	gen rating`i' = .
	replace rating`i' = 1 if tradrtr`i'_ == 1 & progrtr`i'_ == 0
	replace rating`i' = 2 if tradrtr`i'_ == 0 & progrtr`i'_ == 1
	replace rating`i' = 3 if tradrtr`i'_ == 1 & progrtr`i'_ == 1
	replace rating`i' = 4 if tradrtr`i'_ == 0 & progrtr`i'_ == 0
}
kap rating*
kap rating* if gold == 0

*******************************************************************************
* Get estimates for table
*******************************************************************************

gen index = _n
gen item = ""
gen alpha = .
gen withgold = ""
local i = 1
foreach x in trad prog other none {
	krippalpha `x'*
	replace alpha = r(k_alpha) if index == `i'
	replace withgold = "Yes" if index == `i'
	replace item = "`x'" if index == `i'
	local i = `i' + 1
	krippalpha `x'* if gold == 0
	replace alpha = r(k_alpha) if index == `i'
	replace withgold = "No" if index == `i'
	replace item = "`x'" if index == `i'
	local i = `i' + 1	
}

collapse alpha, by(item withgold)
keep if !mi(alpha)

*******************************************************************************
* Format table
*******************************************************************************

tostring alpha, replace format("%20.02fc") force
gen myorder = 1 if item == "trad"
replace myorder = 2 if item == "prog"
replace myorder = 3 if item == "other"
replace myorder = 4 if item == "none"
gsort myorder -withgold
drop myorder

replace item = "Traditionalist" if item == "trad"
replace item = "Progressive" if item == "prog"
replace item = "Other" if item == "other"
replace item = "None" if item == "none"

*******************************************************************************
* Output table
*******************************************************************************

#delimit;

listtex 
	using "_output/tableS1.tex"
	,
	replace
	type rstyle(tabular)
	head(
		\begin{tabular*}
		{0.6\hsize}{@{\hskip\tabcolsep\extracolsep\fill}l*{4}{l}}
		\toprule 
		Category & Gold Items Included & Alpha
		\\
		\midrule
	)
	foot("\bottomrule\end{tabular*}")
	;
	
#delimit cr

*******************************************************************************
* End
*******************************************************************************
